package com.education.wisdom.controller.app;


import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.education.common.core.BaseController;
import com.education.common.utils.BusinessType;
import com.education.common.utils.LogUtil;
import com.education.common.utils.UUIDUtils;
import com.education.wisdom.pojo.Answers;
import com.education.wisdom.pojo.Paper;
import com.education.wisdom.service.IAnswersService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.java.Log;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 答卷 信息操作处理
 * 
 * @author ruoyi
 * @date 2018-11-13
 */
@Controller
@CrossOrigin
@Slf4j
@Api(tags = {"答卷 信息操作处理"})
@RequestMapping("/appAnswers")
public class AppAnswersController extends BaseController
{
    private String prefix = "system/answers";
	
	@Autowired
	private IAnswersService answersService;

	@GetMapping()
	public String answers()
	{
	    return prefix + "/answers";
	}
	
	/**
	 * 查询答卷列表
	 */
	@ApiOperation("答卷信息")
	@GetMapping("/answersList")
	@ResponseBody
	@ApiImplicitParams({
		@ApiImplicitParam(name="djUserid",value="用户编号",required=true,dataType="String"),
		@ApiImplicitParam(name="djType",value="答卷类型",required=true,dataType="Integer"),
		@ApiImplicitParam(name="pageSize",value="分页显示数量",required=true,dataType="Integer"),
		@ApiImplicitParam(name="pageNo",value="当前页",required=true,dataType="Integer")
	})
	public void paperlist(HttpServletResponse response, HttpServletRequest request, Integer pageNo, String djUserid, Integer djType)throws Exception{
		Integer pageSize = 20;
		PageHelper.startPage(pageNo.intValue(), pageSize.intValue());
		log.info(LogUtil.LogInfo("查寻答卷",new Date()));
			Map<String, Object> map = new HashMap<String, Object>();
        	map.put("djUserid", djUserid);
        	map.put("djType", djType);
        	List<Answers> list = answersService.selectAnswersListById(map);
        	writeJSON(new PageInfo<Answers>(list), response,  "200", "成功");
        	
	}

	
	
	/**
	 * 新增保存答卷
	 */
	@ApiOperation("保存答卷")
	@PostMapping("/paperAdd")
	@ResponseBody
	@ApiImplicitParams({
		@ApiImplicitParam(name="djPaperid",value="试卷编号",required=true,dataType="String"),
		@ApiImplicitParam(name="djUserid",value="答题者Id",required=true,dataType="Integer"),
		@ApiImplicitParam(name="djContent",value="答题内容",required=true,dataType="Integer"),
		@ApiImplicitParam(name="djScore",value="答题得分",required=true,dataType="Integer"),
		@ApiImplicitParam(name="djStarttime",value="开始时间",required=true,dataType="Date"),
		@ApiImplicitParam(name="djType",value="类型1正常答完2强制交卷",required=true,dataType="Integer")
	})
	public void paperlist(HttpServletResponse response, HttpServletRequest request, Answers answers)throws Exception{
		
		log.info(LogUtil.LogInfo("保存答卷",new Date()));
			answers.setDjId(UUIDUtils.getByUUId());
			answers.setDjEndtime(new Date());
        	int insertAnswers = answersService.insertAnswers(answers);
        	writeJSON(insertAnswers, response,  "200", "成功");
        	
	}

	
}
